package com.smit.dvb.scan;

import com.smit.adapter.DVBAdapter;
import com.smit.dvb.DVBTunerInfo;
import com.smit.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * DVB搜台控制
 */
public class ScanControl {
    /** 搜台出错 */
    public static final int MSG_SCAN_ERROR = 301;
    /** 搜台开始 */
    public static final int MSG_SCAN_START = 302;
    /** 扫描运营商网络 */
    public static final int MSG_SCAN_DVB_NETWORK = 303;
    /** 锁台 */
    public static final int MSG_SCAN_TUNER_LOCKED = 304;
    /** 搜台进度改变 */
    public static final int MSG_SCAN_PROGRESS_CHANGED = 305;
    /** 搜到节目 */
    public static final int MSG_SCAN_SERVICES_FOUND = 306;
    /** 搜台结束 */
    public static final int MSG_SCAN_FINISH = 307;

    private static final String TAG = "ScanControl";
    private final List<IScanCallback> scanCallbackList = new ArrayList<IScanCallback>();
    /**
     * <p> 添加一个scan回调 <br/>
     * @param callback 回调接口
     */
    public void addCallback(IScanCallback callback) {
        if (!scanCallbackList.contains(callback)) {
            scanCallbackList.add(callback);
        }
    }
    /**
     * <p> 移除一个scan回调 <br/>
     * @param callback 回调接口<br/>
     */
    public void removeCallback(IScanCallback callback) {
        if (scanCallbackList.contains(callback)) {
            scanCallbackList.remove(callback);
        }
    }
    /**
     * <p> 获取所有scan回调对象 <br/>
     * @return 返回所有注册进来的回调
     */
    public List<IScanCallback> getCallbackList() {
        return scanCallbackList;
    }


    /**
     * 自动搜台
     * @param startFreq 起始频点
     * @param endFreq 结束频点
     */
    public void autoScan(int startFreq, int endFreq) {
        LogUtil.debug(TAG, "autoScan startFreq=" + startFreq + " endFreq=" + endFreq);
        DVBAdapter.getInstance().getDVBManager().getDVBService().autoScan(startFreq, endFreq);
    }

    /**
     * 全频点搜台
     * @param startFreq 起始频点
     * @param endFreq 结束频点
     */
    public void fullScan(int startFreq, int endFreq) {
        LogUtil.debug(TAG, "fullScan startFreq=" + startFreq + " endFreq=" + endFreq);
        DVBAdapter.getInstance().getDVBManager().getDVBService().fullScan(startFreq, endFreq);
    }

    /**
     * 手动搜台
     * @param tunerInfo tuner参数
     */
    public void manualScan(DVBTunerInfo tunerInfo) {
        LogUtil.debug(TAG, "manualScan tunerInfo=" + tunerInfo.toString());
        DVBAdapter.getInstance().getDVBManager().getDVBService().manualScan(tunerInfo);

    }

    /**
     * 取消搜台
     */
    public void abortScan() {
        LogUtil.debug(TAG, "abortScan");
        DVBAdapter.getInstance().getDVBManager().getDVBService().abortScan();
    }
}